package com.itheima.tliaswebmanagement.controller;

import com.itheima.tliaswebmanagement.pojo.common.Result;
import com.itheima.tliaswebmanagement.pojo.entity.Emp;
import com.itheima.tliaswebmanagement.pojo.vo.LoginInfo;
import com.itheima.tliaswebmanagement.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description LoginController
 * @Author ziguan ling
 * @Date 2025--01--11
 */
@RestController
@Slf4j
public class LoginController {
    @Autowired
    private EmpService empService;

    @PostMapping("/login")
    public Result login(@RequestBody Emp emp){

        log.info("处理员工登录请求,请求参数: {}", emp);

        LoginInfo loginInfo = empService.getLoginInfo(emp);

        if(loginInfo == null){
            return Result.error("用户名或密码错误");
        }

        return Result.success(loginInfo);
    }


}
